<?php
header('Content-Type: application/json');

$dataFile = '../../data/feedback.json';

try {
    if (!isset($_GET['id'])) {
        throw new Exception('缺少ID参数');
    }
    
    $id = $_GET['id'];
    $data = json_decode(file_get_contents($dataFile), true);
    
    // 删除意见
    $data['feedback'] = array_filter($data['feedback'], function($item) use ($id) {
        return $item['id'] != $id;
    });
    
    // 重新索引数组
    $data['feedback'] = array_values($data['feedback']);
    
    file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT));
    
    echo json_encode(['success' => true]);
    
} catch (Exception $e) {
    http_response_code(500);
    echo json_encode(['success' => false, 'message' => $e->getMessage()]);
}
?> 